/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.inventory.model;


import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.IntegerUtils;
import com.openbravo.pos.util.RoundUtils;
import com.openbravo.bean.erp.viewbean.TimeStoreLine_V;
import com.openbravo.format.Formats;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Administrator
 */
public class TimeStoreLineTableModel extends AbstractTableModel{
     private static String[] columnName=new String[]{
            AppLocal.getIntString("label.prodref"),
            AppLocal.getIntString("label.prodbarcode"),
            AppLocal.getIntString("label.prodname"),
            AppLocal.getIntString("label.prodcategory"),
            AppLocal.getIntString("label.prodpricesell"),
            AppLocal.getIntString("label.attribute"),
            AppLocal.getIntString("label.units")
          };
        List<TimeStoreLine_V> lines;

        public TimeStoreLineTableModel() {
            lines=new ArrayList();
        }

        @Override
        public int getRowCount() {
            return lines.size();
        }

        @Override
        public int getColumnCount() {
            return columnName.length;
        }

        @Override
        public String getColumnName(int column) {
            return columnName[column];
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
             TimeStoreLine_V row=lines.get(rowIndex);
             switch(columnIndex){
                 case 0:
                     return row.getM_sRef();
                 case 1:
                     return row.getM_sCode();
                 case 2:
                     return row.getM_sName();
                 case 3:
                     return row.getCategory();
                 case 4:
                     return RoundUtils.round(row.getM_dPriceSell());
                 case 5:
                     return row.getAttributeset();
                 case 6:
                     return row.getMultiply();
             }
             return null;
        }
        
        private static int[] doubleInt={4,6};
    	
    	@Override
    	public Class<?> getColumnClass(int columnIndex) {
    		if(IntegerUtils.concat(columnIndex, doubleInt))
    			return Double.class;
    		return super.getColumnClass(columnIndex);
    	}
        

        public void resert( List<TimeStoreLine_V> inLines){
            lines=inLines;
            if(lines==null)
                lines=new ArrayList();
            this.fireTableDataChanged();
        }
    }
